package UI;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;

import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;



public class DebuggingFrame{
	  public static void main(String[] args) {
		    theApp = new DebuggingFrame();
		    SwingUtilities.invokeLater(
		       new Runnable() {                          // Anonymous Runnable class object
		                        public void run() {      // Run method executed in thread
		                          theApp.creatGUI();     // Call static GUI creator
		                        }
		                      }       );
		  }
		  // Method to create the application GUI
		  private void creatGUI() {
		    window = new Frame("C* debugger", this);  // Create the app window
		    
		    try {
				UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
			} catch (ClassNotFoundException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (InstantiationException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (IllegalAccessException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (UnsupportedLookAndFeelException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		    
		    window.getContentPane().setLayout(new BorderLayout());
		    //window.getContentPane().add(BorderLayout.CENTER, buildInfinitePanel());
		    //System.out.println("error");
		    Toolkit theKit = window.getToolkit();        // Get the window toolkit
		    Dimension wndSize = theKit.getScreenSize();  // Get screen size

		    // Set the position to screen center & size to half screen size
		    window.setBounds(0,0,wndSize.width,wndSize.height-30);
		    window.addWindowListener(new WindowHandler());// Add window listener
		    try {
				view = new View(this);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}                 // Create the view
		    //window.pack();
		    window.setVisible(true);
		  }

		  
		  // Return a reference to the application window
		  public Frame getWindow() { 
		     return window; 
		  }

		  
		  class WindowHandler extends WindowAdapter {
		    // Handler for window closing event
			    public void windowClosing(WindowEvent e) {
			    	e.getWindow().dispose();
			    }
			    
			    public void windowLostFocus(WindowEvent e){
			    	e.getWindow().toFront();
			    }
		  }

		  private  Frame window;                   // The application window
		  private  View view;
		  private static DebuggingFrame theApp;               // The application object
		public View getView() {
			return view;
		}
		public void setView(View view) {
			this.view = view;
		}
		
			
}

